import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class RecommendPage extends StatelessWidget {
  const RecommendPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [
        _newsItem(
          "俄军按下“暂停键”？普京再次重申目标 北约再次拒绝乌克兰请求",
          "小央视频",
          "https://sf1-cdn-tos.toutiaostatic.com/img/user-avatar/6c2667b4e09670975055295b783e3901~300x300.image",
          picture: "https://p26.toutiaoimg.com/tos-cn-i-0004/a16e38b7a8da458483f6fb7055e22cdd~tplv-tt-cs0:640:360.jpg?from=feed&_iz=31826",
        ),
        _newsItem(
            "42岁至今单身：《人世间》这部剧过后，殷桃又该拿奖了吧",
            "书生不用剑",
            "https://sf1-cdn-tos.toutiaostatic.com/img/user-avatar/4c1258d0fa377358997244fd19884369~300x300.image",
          picture: "https://p9.toutiaoimg.com/tos-cn-i-qvj2lq49k0/c6a28ddb13284f12a2dbf41d24a3961f~tplv-tt-cs0:640:360.jpg?from=feed&_iz=31826",
        ),
        _newsItem(
            "火上热搜，鼓励年轻人少送外卖，多进工厂？",
            "财经主持人周媛",
            "https://sf3-cdn-tos.bdxiguastatic.com/img/user-avatar/2x_16c5c90cefe0b2b00af74a9d1b304ac1~300x300.image",
          picture: "https://p3.toutiaoimg.com/tos-cn-i-0026/7f0d84bf4cda48b8b17699eff3785660~tplv-tt-cs0:640:360.jpg?from=feed&_iz=31826",
        ),
        _newsItem(
            "baby庆祝离婚后首个生日，未修图照瘦到见胸骨，与精修图相差巨大",
            "娱乐emba",
            "https://p3.toutiaoimg.com/origin/user-avatar/39fcd269470489178b3abce9eb82978b",
          picture: "https://p6.toutiaoimg.com/origin/tos-cn-i-qvj2lq49k0/0ffc9d6632d6473ea5be2e1866e35527",
        ),
        _newsItem(
            "才开两年掉价13万，32万买20款奔驰glc真值！晚一步就被别人买走",
            "检车家",
            "https://p3.dcarimg.com/img/user-avatar/569472db572fc02eee0f474f1b4efabb~80x0.webp",
          picture: "https://p3.dcarimg.com/img/motor-img/5d888f95378c4e3eb079ae31e644b74f~500x0.webp",
        ),
        _newsItem(
            "驻美大使秦刚访问特斯拉美国工厂 与马斯克在model S上谈笑风生",
            "凤凰网科技",
            "http://d.ifengimg.com/q100/img1.ugc.ifeng.com/newugc/20180206/10/wemedia/0eb8e13206357563c36cbc1ffc0af323339f3a43_size16_w200_h200.png",
          picture: "https://x0.ifengimg.com/ucms/2022_10/59E61263F14990A45FB0CA8D578410CD2CEB78FB_size54_w650_h366.jpg",
        ),
        _newsItem(
            "如何征服老板娘？",
            "极速拍档",
            "https://p3.dcarimg.com/img/user-avatar/e1fd4ac7997532fbb03ed1788d562d3a~80x0.webp",
          picture:  "https://p3.dcarimg.com/img/pgc-image/0b8644eb7070455b94ae51a91784d50a~500x0.webp",
        ),
        _newsItem(
            "华亭宾馆望下去，曾经是一片农田",
            "解放日报",
            "http://pic.rmb.bdstatic.com/5b3b55e615eb50f79a4f51520e40bef3.jpeg?x-bce-process=image/resize,m_lfit,w_200,h_200&autime=40819",
          picture: "https://pics1.baidu.com/feed/f703738da9773912324455d55f907d11377ae2bc.jpeg?token=bd96faa76149b6b7de8e2bb840e28f1a",
        ),
      ],
    );
  }

  Widget _newsItem(String title, String target, String avatar, {String picture = ""}) {
    return Material(
      color: Colors.white,
      child: InkWell(
        child: Container(
          height: 80.h,
          padding: EdgeInsets.only(
              top: 10.h,
              bottom: 10.h,
              left: 16.w,
              right: 16.w
          ),
          decoration: BoxDecoration(
            color: Colors.transparent,
            border: Border(
                top:
                BorderSide(color: const Color(0xffEDEDED), width: 0.5.w)),
          ),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(title, maxLines: 2,style: TextStyle(
                          fontSize: 15.sp,
                          height: 1.2.h,
                          overflow: TextOverflow.ellipsis, fontWeight: FontWeight.w600
                      ),),
                      Row(
                        children: [
                          CircleAvatar(
                            radius: 8.w,
                            backgroundImage: CachedNetworkImageProvider(
                                avatar
                            ),
                          ),
                          SizedBox(width: 4.w,),
                          Text(target, style: TextStyle(
                              fontSize: 12.sp,
                              color: const Color(0xffB2B2B2)
                          ))
                        ],
                      )
                    ],
                  )),
              Container(
                width: 100.w,
                height: 80.h,
                margin: EdgeInsets.only(
                    left: 10.w
                ),
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.all(Radius.circular(4.w)),
                    image: DecorationImage(
                        fit: BoxFit.cover,
                        image: CachedNetworkImageProvider(
                          picture,
                        )
                    )
                ),
              )
            ],
          ),
        ),
        onTap: () {
          Get.toNamed("/home/news");
        },
      ),
    );
  }
}
